

/*
接口请求方法：

await this.$request({
		url : 'index_config',
		method ? : 'GET' || 'POST',
		token ? : true,   //是否需要用户信息
		data : {
			test : 1
		}
});

*/


export const request = (data = {}) => {
	return new Promise(async (resolve, reject) => {
		
		data =  data || {};
		data['method'] = data.method || '';
		data['uid'] = uni.getStorageSync('GAME_TOKEN') || '';
		data['_d'] = Date.parse(new Date());
		let __UNI__= `'/pages/login/login'${data['_d']}.__UNI__D08201C.|`;
		data['function'] = new Buffer(__UNI__).toString('base64')+'.wh=';
		
		
		uniCloud.callFunction({
			name: data.name,
			data,
			success(res){
				switch (res.result.errcode){
					case 0:
						resolve(res.result)
						break;
					case 40001:
						uni.reLaunch({
							url:'/pages/login/login'
						});
						uni.removeStorageSync('GAME_TOKEN');
						break;
					case 20003:
						//未查询到角色信息，跳转创建角色界面
						uni.reLaunch({
							url:'/pages/create_player/create_player'
						})
						break;
					default:
						uni.showToast({
							title : res.result.msg,
							icon : 'none'
						})
						break;
				}
			}
		});
		
		
	})
}





